package com.qinggeng.project.system.service.impl;

import com.qinggeng.common.utils.DateUtils;
import com.qinggeng.project.api.dto.SysAdverDto;
import com.qinggeng.project.system.domain.SysAdver;
import com.qinggeng.project.system.mapper.SysAdverMapper;
import com.qinggeng.project.system.service.ISysAdverService;
import com.qinggeng.project.system.service.ISysMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 广告管理Service业务层处理
 *
 * @author qinggeng
 * @date 2020-02-12
 */
@Service
public class SysAdverServiceImpl implements ISysAdverService
{
    @Resource
    private SysAdverMapper adverMapper;

    private  static  final  Long ID=1000L;
    /**
     * 查询广告管理
     *
     * @param adverId 广告管理ID
     * @return 广告管理
     */
    @Override
    public SysAdver selectSysAdverById(Long adverId)
    {
        return adverMapper.selectSysAdverById(adverId);
    }

    /**
     * 查询广告管理列表
     *
     * @param sysAdver 广告管理
     * @return 广告管理
     */
    @Override
    public List<SysAdver> selectSysAdverList(SysAdver sysAdver)
    {
        return adverMapper.selectSysAdverList(sysAdver);
    }

    /**
     * 新增广告管理
     *
     * @param sysAdver 广告管理
     * @return 结果
     */
    @Override
    public int insertSysAdver(SysAdver sysAdver)
    {
        sysAdver.setCreateTime(DateUtils.getNowDate());
        return adverMapper.insertSysAdver(sysAdver);
    }

    /**
     * 修改广告管理
     *
     * @param sysAdver 广告管理
     * @return 结果
     */
    @Override
    public int updateSysAdver(SysAdver sysAdver)
    {
        sysAdver.setUpdateTime(DateUtils.getNowDate());
        return adverMapper.updateSysAdver(sysAdver);
    }

    /**
     * 批量删除广告管理
     *
     * @param adverIds 需要删除的广告管理ID
     * @return 结果
     */
    @Override
    public int deleteSysAdverByIds(Long[] adverIds)
    {
        return adverMapper.deleteSysAdverByIds(adverIds);
    }

    /**
     * 删除广告管理信息
     *
     * @param adverId 广告管理ID
     * @return 结果
     */
    @Override
    public int deleteSysAdverById(Long adverId)
    {
        return adverMapper.deleteSysAdverById(adverId);
    }

    @Override
    public SysAdverDto getInvitActivity() {
        SysAdver adver = adverMapper.selectSysAdverById(ID);
        if (null ==adver){
            return null;
        }
        SysAdverDto sysAdverDto = new SysAdverDto();
        sysAdverDto.setUrl(adver.getAdverImg());//广告图片地址
        sysAdverDto.setIsReturn(adver.getAdverType()); //跳转类型（0=不跳转，1=原生界面，2=h5页面）
        //内部链接
        if (adver.getAdverType().equals("1")) {
            sysAdverDto.setCode("1000");
            sysAdverDto.setArg(String.valueOf(adver.getGoodsId()));
        }
        //外部链接（H5页面）
        if (adver.getAdverType().equals("2")) {
            sysAdverDto.setArg(adver.getAdverHref());
        }
        return  sysAdverDto;
    }

}
